
#pragma once

#include <websocketpp.hpp>
#include <boost/shared_ptr.hpp>
#include <ConnectionBroker/server/WebSocketServer.h>

#include <map>
#include <string>
#include <vector>

using websocketpp::server;
using websocketpp::server_tls;

namespace ConnectionBroker 
{
   class WebSocketServer;
   template <typename endpoint_type>
   class WebSocketServerHandler : public endpoint_type::handler
   {

   public: //Constructors, destructor
      WebSocketServerHandler(ConnectionBroker::WebSocketServer* pServer, boost::shared_ptr<boost::asio::ssl::context> pContext) : endpoint_type::handler(), mServer(pServer), mContext(pContext) {}
      virtual ~WebSocketServerHandler() {}

   protected: //Member variables
      ConnectionBroker::WebSocketServer* mServer;
      boost::shared_ptr<boost::asio::ssl::context> mContext;

   public:
      boost::shared_ptr<boost::asio::ssl::context> on_tls_init() { return mContext; }
      void on_open(typename endpoint_type::handler::connection_ptr con)
      {
         mServer->webSocketClientFactory<typename endpoint_type>(con);
      }
      void on_close(typename endpoint_type::handler::connection_ptr con)
      {
         mServer->webSocketClientRemove<typename endpoint_type>(con);
      }
      void on_message(typename endpoint_type::handler::connection_ptr con, typename endpoint_type::handler::message_ptr msg)
      {
         mServer->onMessage<typename endpoint_type>(con, msg);
      }

   };

}

